'''
Created on Apr 3, 2012

@author: loic
'''
import eyeD3
import sys
import unicodedata
#from eyeD3 import *
#from eyeD3.tag import *
from eyeD3.frames import *
#from eyeD3.utils import *

#ENCODING = locale.getpreferredencoding();
TRACE = 1
class mp3(eyeD3.Tag):
    def get_frames_as_text(self):
        frames_as_text = {}
        from string import maketrans
        trantab = maketrans(u' .', u'__')
        for f in self.frames:
            try:
#            if 1:
                txt=f.as_text()
#                print txt
#                tr = txt.replace(' ', '_').replace('.', '_')
                frames_as_text[f.header.id] = unicode(txt)
#                self.frames_as_text['_'+f.header.id] = tr
            except:
                pass
        return frames_as_text
        
def replace_sep(txt, sep = ' .'):
    for s in sep:
        txt = txt.replace(s, '_')
    return txt

if __name__ == '__main__':
    #tag = eyeD3.Tag()
    tag = mp3()
    eyeD3.utils.TRACE=1
#    tag.encoding = eyeD3.frames.UTF_8_ENCODING
    eyeD3.frames.FORCE_ENCODING = eyeD3.frames.UTF_8_ENCODING
    #tag.input_enc = "utf8"
    tag.link(sys.argv[1])
    frames = tag.get_frames_as_text()
    
    for f in frames:
        try:
            print "%s : %s" % (f, frames[f])
        except:
            pass
#    if 'TRDA' in frames:
#        sp = frames['TRDA'].split('.')
#        frames['TRDA'] = "%s%s%s" % (sp[2], sp[1], sp[0])
#    print "%(TRDA)s_%(_TALB)s" % frames

